package com.xs.tool.dao;

import com.xs.tool.model.User;
import java.util.List;

import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

/**
 *
 */
//public interface UserDao extends CrudRepository<User,Integer> {
public interface UserDao extends JpaRepository<User, Integer> {
  User findByName(String name);
  /**
   * Query creation
   * this translates into the following query:
   * select u from ToolTest u where u.id_card = ?1
   */
  @Override
  User getOne(Integer id);
  /**
   * find all ToolTest
   * @param sort
   * @return
   */
  @Override
  List<User> findAll(Sort sort);
  @Override
  void delete(User user);

  /**
   * update a usr by Modifying Queries
   * @param token
   * @param id
   * @return
   */
  @Modifying
  @Query("update User u set u.token = ?1 where u.id = ?2")
  int updateUser(String token, Integer id);
}
